// 更新用户
const cloud = require('wx-server-sdk');
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
exports.main = async (event, context) => {
  if (!event.openId) {
    return {
      msg: "缺少openId",
      code: 500
    }
  }
  // 对用户表更新一个用户
  const res = await db.collection('user').where({
    openId: event.openId,
  }).update({
    data: {
      avatar: event.avatarUrl,
      gender: event.gender,
      userName: event.nickName,
    }
  });
  return res;
}